package br.com.equus.entidade;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.envers.Audited;
import org.hibernate.validator.constraints.Email;

import br.com.arquitetura.entidade.Entidade;
import br.com.arquitetura.util.StringUtil;

@Entity
@Table(name = "EQ_FORNECEDOR", catalog = "EQUUS")
@Audited
public class Fornecedor extends Entidade<Integer> {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "ID_FORNECEDOR", unique = true, nullable = false)
	private Integer id;

	@Column(name = "DSC_RAZAO", nullable = false, length = 255)
	private String razaoSocial;

	@Column(name = "DSC_ENDERECO", nullable = false, length = 500)
	private String endereco;

	@Column(name = "CNPJ", nullable = false, length = 20)
	private String cnpj;

	@Column(name = "DSC_TEL", length = 255)
	private String telefone;

	@Email(message = "Email inválido")
	@Column(name = "DSC_EMAIL", length = 255)
	private String email;

	@Transient
	private String cnpjFormat;

	public Fornecedor() {
		// TODO Auto-generated constructor stub
	}

	public Fornecedor(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getRazaoSocial() {
		return razaoSocial;
	}

	public void setRazaoSocial(String razaoSocial) {
		this.razaoSocial = razaoSocial;
	}

	public String getEndereco() {
		return endereco;
	}

	public void setEndereco(String endereço) {
		this.endereco = endereço;
	}

	public String getCnpj() {
		return cnpj;
	}

	public void setCnpj(String cnpj) {
		this.cnpj = cnpj;
	}

	public String getTelefone() {
		return telefone;
	}

	public void setTelefone(String telefone) {
		this.telefone = telefone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getCnpjFormat() {
		if (cnpj != null && !cnpj.isEmpty()) {
			return StringUtil.format("##.###.###/####-##", cnpj);
		}
		return cnpjFormat;
	}

	public void setCnpjFormat(String cnpjFormat) {
		this.cnpjFormat = cnpjFormat;
	}

}
